package com.hehua.FactoryMethodTwo;

import org.w3c.dom.Document;

import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;

/**
 * @author hehua
 * @Date 2022-04-17
 * xml文件读取类
 */
public class XmlUtil {
    public static Object getBean() throws Exception {
        DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
        DocumentBuilder builder = factory.newDocumentBuilder();
        Document document = null;
        document = builder.parse("src//com//hehua//FactoryMethodTwo//FactoryMethod.xml");
        String nodeValue = document.getElementsByTagName("className").item(0).getFirstChild().getNodeValue();
        Class<?> aClass = Class.forName(nodeValue);
        Object o = aClass.newInstance();
        return o;
    }
}
